-
-
Notifications
You must be signed in to change notification settings - Fork 78.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow modal options to be changed after instantiation #5514
Conversation
Maybe they caches the result for repeated opening modal. $('#html_modal').on('hidden',function(){
$(this).removeData('modal');
$('#html_modal .modal_label').text('default_label');
$('#html_modal .modal_body').html('default_body');
}); |
@cielavenir Yes, you could do this yourself, although I haven't tested your code. I think it would be useful for this to be in bootstrap, but It's not up to me. One difference between your code and my proposed change is that in your code all previous options are wiped. I'd like the new options to extend the previous options so that you don't have to respecify them, although I'm open to discussions on this. Unfortunately, there's a nasty bug I've just spotted in that the default options always override previous options, so I'm closing this request until I get that fixed. |
Fixed the bug; the delete avoids cyclic references in data, and the semicolon is to keep jshint happy. A perhaps more elegant solution would be to change the line , options = $.extend(..., $this.data(), ...) to something like , options = $.extend(..., _.pluck($this.data(), 'backdrop', 'keyboard', 'show', 'remote'), ...) to avoid storing unused data attributes in options. We would need |
you can change the modal options at any time by just accessing the raw class obj. $myElement.data('modal').options = { … } |
I'd like to see this issue re-opened and addressed. Allowing modals to change after instantiation would allow for multiple buttons to reuse one hidden div (see #5161 (comment) and http://stackoverflow.com/questions/14045515/how-can-i-reuse-one-bootstrap-modal-div). |
|
When you call modal on an element, bootstrap will currently always use the options passed in the first call. This pull request allows subsequent calls to modal with different options to change the behaviour of the modal.